package main

import (
	"fmt"
	"sync"
	"time"
)

var x int
var wg sync.WaitGroup
var lock sync.RWMutex
var l sync.Mutex

func read() {
	lock.RLock()
	time.Sleep(time.Millisecond)
	lock.RUnlock()

	wg.Done()
}
func write() {

	lock.Lock()
	x = x + 1
	lock.Unlock()
	time.Sleep(time.Millisecond * 10)

	wg.Done()
}

func main() {
	start := time.Now()
	//并发数量 read+ write 数量 或者 写在for 里 wg.Add(1)
	// wg.Add(222 + 2022222)
	for i := 0; i < 222; i++ {
		wg.Add(1)
		go write()

	}

	for i := 0; i < 20222; i++ {
		wg.Add(1)
		go read()
	}

	wg.Wait()
	fmt.Println(time.Since(start))
}
